package org.kumas.sgrpc.remoting.transport.dispatcher;

import java.util.concurrent.ExecutorService;

import org.kumas.sgrpc.common.URL;
import org.kumas.sgrpc.remoting.Channel;
import org.kumas.sgrpc.remoting.ChannelHandler;
import org.kumas.sgrpc.remoting.ExecutionException;
import org.kumas.sgrpc.remoting.RemotingException;
import org.kumas.sgrpc.remoting.transport.dispatcher.ChannelEventRunnable.ChannelState;

/**
 *
 * @author KumasZhang
 * @version 1.0
 * @since 2021-07-13 15:52
 */
public class AllChannelHandler extends WrappedChannelHandler {

    public AllChannelHandler(ChannelHandler handler,
        URL url) {
        super(handler, url);
    }

    @Override
    public void connected(Channel channel) throws RemotingException {
        ExecutorService executor = getSharedExecutorService();
        try {
            executor.execute(new ChannelEventRunnable(channel, handler, ChannelState.CONNECTED));
        } catch (Throwable t) {
            throw new ExecutionException("connect event", channel, getClass() + " error when process connected event .", t);
        }
    }

    @Override
    public void disconnected(Channel channel) throws RemotingException {
        super.disconnected(channel);
    }

    @Override
    public void received(Channel channel, Object message) throws RemotingException {
        super.received(channel, message);
    }

    @Override
    public void caught(Channel channel, Throwable exception) throws RemotingException {
        super.caught(channel, exception);
    }
}
